package com.basic.system.controller;

import com.basic.common.constant.CommonDsConstant;
import com.basic.common.result.WebResult;
import com.basic.system.dao.model.Dictionary;
import com.basic.system.domain.DictionaryBo;
import com.basic.system.domain.DictionaryDto;
import com.basic.system.domain.DictionaryInsertDto;
import com.basic.system.domain.bo.DictionarDictIdVo;
import com.basic.system.domain.bo.DictionaryVo;
import com.basic.system.service.DictionaryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/dictionary/")
public class DictionaryController {
    @Autowired
    private DictionaryService dictionaryService;
    //插入数据
    @PostMapping("insertSelective")
    public WebResult insertSelective(@RequestBody DictionaryInsertDto dictionary){
        return dictionaryService.insertSelective(dictionary);
    }
    //查询返回List
    @PostMapping("selectByExample")
    public WebResult selectByExample(@RequestBody DictionaryVo dictionaryVo){
        DictionaryBo dictionaryBo=new DictionaryBo();
        BeanUtils.copyProperties(dictionaryVo,dictionaryBo);
        List<Dictionary> dictionaries = dictionaryService.selectByExample(dictionaryBo);
        return WebResult.success(dictionaries);
    }
    //修改数据
     @PostMapping("updateById")
    public WebResult updateById(@RequestBody DictionaryDto dictionaryDto){
        Dictionary dictionary=new Dictionary();
        BeanUtils.copyProperties(dictionaryDto,dictionary);
        dictionary.setUpdateDate(new Date());
        return dictionaryService.updateByPrimaryKeySelective(dictionary);
    }
    //分页查询
    @PostMapping("pageSelect")
    public WebResult pageSelect(@RequestBody DictionaryBo dictionaryBo){
        return WebResult.success(dictionaryService.selAlarmPersonSetDetailListByPage(dictionaryBo));
    }
    //批量删除
    @PostMapping("deleteList")
    public WebResult selectList(@RequestBody DictionaryBo dictionaryBo){
        return dictionaryService.deleteList(dictionaryBo.getIds());
    }
    //根据code和DictId查询
    @PostMapping("selectByDictIdCodeId")
    public WebResult selectByDictIdCodeId(@RequestBody DictionaryVo dictionaryVo){
        Dictionary dictionary=new Dictionary();
        BeanUtils.copyProperties(dictionaryVo,dictionary);
        List<Dictionary> d = dictionaryService.selectListByDictIdCodeId(dictionary);
        return WebResult.success(d);
    }
    //根据code和DictId分页查询
    @PostMapping("selectListByDictIdCodePageInfo")
    public WebResult selectListByDictIdCodePageInfo(@RequestBody DictionaryBo dictionaryBo){
        PageInfo pageInfo = dictionaryService.selectListByDictIdCodePageInfo(dictionaryBo);
        return WebResult.success(pageInfo);
    }
    //下拉框
//    @ModelAttribute("pumpStationTypes")
    @PostMapping("getPumpStationTypes")
    public List<DictionarDictIdVo> getPumpStationTypes(@RequestBody Dictionary dictionary) {
        return dictionaryService.getPumpStationTypes(dictionary.getDictId());
    }
}
